//
//  YMRepresentable.swift
//  YMSwiftUI
//
//  Created by anscen on 2022/4/26.
//
//
import SwiftUI
import WebKit

struct YMWebView: UIViewRepresentable {
    @State var urlString :String
    func makeUIView(context: Context) -> some UIView {
        return WKWebView()
    }
    func updateUIView(_ uiView: UIViewType, context: Context) {
        guard let url = URL(string: urlString) else { return }
        let request = URLRequest(url:url)
        if let webView = uiView as? WKWebView{
            webView.load(request)
        }
    }
}
struct YMLabel :UIViewRepresentable{
    var title :String
    func makeUIView(context: Context) -> some UIView {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 20, weight: .medium)
        label.textColor = UIColor.red
        label.textAlignment = .center
        label.text = title
        return label
    }
    func updateUIView(_ uiView: UIViewType, context: Context) {
        
    }
}
struct YMCaseCell :UIViewRepresentable{
    var model :YMBook
    func makeUIView(context: Context) -> some UIView {
        let view = YMCaseView.instanceView()
        view.frame = CGRect(x:0, y: 0, width: SCREEN_WIDTH, height: 105)
        return view
    }
    func updateUIView(_ uiView: UIViewType, context: Context) {
        if let cell = uiView as? YMCaseView{
            cell.model = model
        }
    }
}
struct YMAboutView :UIViewRepresentable{
    func makeUIView(context: Context) -> some UIView {
        return YMAboutController().view
    }
    func updateUIView(_ uiView: UIViewType, context: Context) {
        
    }
}
struct YMNavigationViewController :UIViewControllerRepresentable{
    var vc : UIViewController
    func makeUIViewController(context: Context) -> some UIViewController {
        let nvc = BaseNavigationController.init(rootViewController: vc)
        return nvc
    }
    func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
//        if let nvc = uiViewController as? UINavigationController{
//            nvc.viewControllers.first?.title = title
//        }
    }
}



